package com.myBlog.controller;

import com.myBlog.domain.ResponseResult;
import com.myBlog.domain.dto.AddArticleDTO;
import com.myBlog.domain.dto.ArticleDTO;
import com.myBlog.domain.vo.PageVo;
import com.myBlog.service.ArticleService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/content/article")
public class ArticleController {

    @Resource
    private ArticleService articleService;

    /**
     * 添加文章
     *
     * @param articleDTO
     * @return
     */
    @PostMapping
    public ResponseResult add(@RequestBody AddArticleDTO articleDTO) {

        return articleService.add(articleDTO);
    }

    /**
     * 文章分页查询
     *
     * @param pageNum
     * @param pageSize
     * @param articleDTO
     * @return
     */
    @GetMapping("/list")
    public ResponseResult<PageVo> list(Integer pageNum, Integer pageSize, ArticleDTO articleDTO) {
        return articleService.list(pageNum, pageSize, articleDTO);
    }

    /**
     *  根据文章id查询文章内容
     * @param articleId
     * @return
     */
    @GetMapping("{id}")
    public ResponseResult getArticleInfo(@PathVariable("id") Long articleId) {
        return articleService.getArticleInfo(articleId);
    }

    /**
     *  根据id集合删除文章
     * @param ids
     * @return
     */
    @DeleteMapping("{id}")
    public ResponseResult delete(@PathVariable("id") List<Long> ids) {
        return articleService.deleteById(ids);
    }

    /**
     * 修改文章内容
     * @param articleDTO
     * @return
     */
    @PutMapping
    public ResponseResult updateArticle(@RequestBody AddArticleDTO articleDTO) {
        return articleService.updateArticleInfo(articleDTO);
    }
}
